package com.teckteam.ptvsystem.view;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.teckteam.ptvsystem.controller.GeocodeResultsML;

/**
 * Representation of row elements in geocoding results "table"
 *
 */
public class GeocodeResultRowPanel extends JPanel
{
   private JLabel addrLabel, rankLabel, latLabel, lonLabel; 
   private GeocodePrompt gp;
   /**
    * Constructor to populate the JPanel from scraped data.
    * 
    * @param args
    * @param geocodePrompt 
    */
   public GeocodeResultRowPanel(String[] args, GeocodePrompt gp)
   {
      //Args format: 0:address, 1:accuracyrank, 2:suburb, 3:latitude, 4:longitude
      addrLabel = new JLabel(String.format("%s, %s", args[0], args[2]));
      rankLabel = new JLabel(args[1]);
      latLabel = new JLabel(args[3]);
      lonLabel = new JLabel(args[4]);
      this.gp = gp;
      
      //Mouse actions
      addMouseListener(new GeocodeResultsML(this));
      
      setLayout(new GridLayout(1, 3));
      setBorder(BorderFactory.createLineBorder(Color.BLACK));
      JPanel coord = new JPanel(new FlowLayout(FlowLayout.LEFT));
      
      coord.add(latLabel);
      coord.add(lonLabel);
      coord.setBackground(Color.YELLOW);
      add(rankLabel, 0);
      add(addrLabel, 1);
      add(coord, 2);
   }
   
   /**
    * Collect GPS coordinates attached to panel row and pass it to parent dialog.
    */
   public void setGPSCoords()
   {
      gp.setGPSCoords(latLabel.getText(), lonLabel.getText(), addrLabel.getText());
   }
   
}
